/**
 * Created by jack on 2017/12/14.
 */
'use strict';

goog.provide('Blockly.Python.motion');

goog.require('Blockly.Python');


Blockly.Python['motion_movesteps'] = function(block) {
  var value_steps = Blockly.Python.valueToCode(block, 'STEPS', Blockly.Python.ORDER_ATOMIC);
  // TODO: Assemble Python into code variable.
   var code = 'await self.figure_move(['+value_steps+',0])\n';
  return code;
};


Blockly.Python['motion_turnright'] = function(block) {
  var value_rotates = Blockly.Python.valueToCode(block, 'DEGREES', Blockly.Python.ORDER_ATOMIC);
  // TODO: Assemble Python into code variable.
  var code = 'await self.figure_rotate(['+value_rotates+',0])\n';
  return code;
};

Blockly.Python['motion_turnleft'] = function(block) {
  var value_rotates = Blockly.Python.valueToCode(block, 'DEGREES', Blockly.Python.ORDER_ATOMIC);
  // TODO: Assemble Python into code variable.
  var code = 'await self.figure_rotate([-'+value_rotates+',0])\n';
  return code;
};


Blockly.Python['motion_pointindirection'] = function(block) {
  var value_rotates = Blockly.Python.valueToCode(block, 'DIRECTION', Blockly.Python.ORDER_NONE);
  // TODO: Assemble Python into code variable.
  var code = 'await self.figure_rotateTo(['+value_rotates+',0])\n';
  return code;
};

Blockly.Python['motion_gotoxy'] = function(block) {
    var value_x = Blockly.Python.valueToCode(block, 'X', Blockly.Python.ORDER_ATOMIC);
    var value_y = Blockly.Python.valueToCode(block, 'Y', Blockly.Python.ORDER_ATOMIC);
    var code = 'await self.figure_moveTo(['+value_x+','+value_y+',0])\n';
    return code;
};

Blockly.Python['motion_setx'] = function(block) {
    var value_x = Blockly.Python.valueToCode(block, 'X', Blockly.Python.ORDER_ATOMIC);
    var code = 'await self.figure_moveTo(['+value_x+',"NaN",0])\n';
    return code;
};


Blockly.Python['motion_sety'] = function(block) {
    var value_y = Blockly.Python.valueToCode(block, 'Y', Blockly.Python.ORDER_ATOMIC);
    var code = 'await self.figure_moveTo(["NaN",'+value_y+',0])\n';
    return code;
};

Blockly.Python['motion_xposition'] = function(block) {
   var code="await self.figure_x(None)";
    return [code, Blockly.Python.ORDER_ATOMIC];
};

Blockly.Python['motion_yposition'] = function(block) {
   var code="await self.figure_y(None)";
    return [code, Blockly.Python.ORDER_ATOMIC];
};

Blockly.Python['motion_direction'] = function(block) {
   var code="await self.figure_r(None)";
    return [code, Blockly.Python.ORDER_ATOMIC];
};
